package com.wenlin.myproduction.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenlin.myproduction.R;
import com.wenlin.myproduction.bean.NumberBean;
import com.wenlin.myproduction.util.UI;

import me.drakeet.multitype.ItemViewBinder;

public class NumberShowBinder extends ItemViewBinder<NumberBean, NumberShowBinder.VH> {
    private OnLongClickListener listener;

    public NumberShowBinder(OnLongClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected VH onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        return new VH(inflater.inflate(R.layout.item_number, parent, false));
    }

    @Override
    protected void onBindViewHolder(@NonNull VH holder, @NonNull NumberBean item) {
        UI.setText(holder.tv, item.getNumber());
        UI.setOnLongClickListener(holder.tv, v -> {
            if (listener != null) {
                listener.onLongClick(holder);
            }
            return true;
        });
    }

    public static class VH extends RecyclerView.ViewHolder {
        TextView tv;

        public VH(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
        }
    }

    public interface OnLongClickListener {
        void onLongClick(VH vh);
    }
}
